'''
Author: xubing xubing613@foxmail.com
Date: 2025-08-06 11:06:04
LastEditors: xubing xubing613@foxmail.com
LastEditTime: 2025-08-08 12:23:53
FilePath: /questionnaire-fix-proj/test.py
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
'''
from openai import OpenAI
import pandas as pd

client = OpenAI(
    # 若没有配置环境变量，请用百炼API Key将下行替换为：api_key="sk-xxx",
    # api_key="sk-97e1348aed39485492ff2645c850f4c9",
    api_key="sk-2eea77e26a464c25b91d2e6a45aebd55",
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)

df = pd.read_excel("query_20250520_resp_2.5_vs_3_man.xlsx")


def test_qwen3_client_chat(model_name, sys_content, history):
    # messages= [{"role": "system","content": sys_content}] + eval(history)
    messages = [{"role": "system", "content": sys_content}] + history
    print(messages)
    completion = client.chat.completions.create(
        # 模型列表：https://help.aliyun.com/zh/model-studio/getting-started/models
        model=model_name,
        messages=messages,
        # Qwen3模型通过enable_thinking参数控制思考过程（开源版默认True，商业版默认False）
        # 使用Qwen3开源版模型时，若未启用流式输出，请将下行取消注释，否则会报错
        extra_body={"enable_thinking": False},
    )
    print(completion.choices[0].message.content)
    # print(type(completion.model_dump_json()))


# print(df)
i = 194
sys_content = df.iloc[i]["系统Prompt"]
history = df.iloc[i]["历史对话"]

full_history = eval(history) + [{"role": "assistant", "content": df.iloc[i]["qwen2.5-72b"]},{"role": "user", "content": df.iloc[i]["用户回复"]}]
print(full_history)

models = "qwen3-14b "  #["qwen3-1.7b","qwen3-0.6b","qwen3-8b","qwen3-14b",'qwen3-32b',"qwen3-30b-a3b-instruct-2507",]
# for model in models:
#     print("model: ", model)
# test_qwen3_client_chat(models, sys_content, full_history)
# print(sys_content)

new_full = []
# full_history = [
#     {"用户":x["content"] if x["role"] == "user" else "助手":x["content"] } 
#     for x in full_history
#     ]
for x in full_history:
    if x["role"] == "user":
        new_full.append({"用户":x["content"]})
    else:
        new_full.append({"助手":x["content"]})
print(new_full)